<template>
  <div>
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane v-if="glevel === 2" label="群众举报" name="first">
        <Table
          :tableColumn="tableColumn"
          :tableData="tableData"
          :activeName="activeName"
          @publicList="publicList"
          :total="total"
          @page="page"
          ref="child"
        ></Table>
      </el-tab-pane>

      <el-tab-pane v-if="glevel === 2" label="我的巡视" name="second">
        <!-- <Table
          :tableColumn="tableColumn"
          :tableData="tableData"
          :activeName="activeName"
          @publicList="publicList"
          ref="child"
          :total="total"
        ></Table> -->
      </el-tab-pane>
      <el-tab-pane v-else-if="glevel !== 2" label="下级反馈" name="second">
        <Table
          :tableColumn="tableColumn"
          :tableData="tableData"
          :activeName="activeName"
          @publicList="publicList"
          :total="total"
          @page="page"
          ref="child"
        ></Table>
      </el-tab-pane>
      <el-tab-pane label="整改到期" name="third">
        <Table
          :tableColumn="tableColumn"
          :tableData="tableData"
          :activeName="activeName"
        ></Table>
      </el-tab-pane>

      <el-tab-pane label="上级督办" name="fourth">
        <Table
          :tableColumn="tableColumn"
          :tableData="tableData"
          :activeName="activeName"
          @publicList="publicList"
          ref="child"
          :total="total"
        ></Table>
      </el-tab-pane>

      <el-tab-pane label="已处理" name="five">
        <Table
          :tableColumn="tableColumn"
          :tableData="tableData"
          :activeName="activeName"
          @publicList="publicList"
          ref="child"
          :total="total"
        ></Table>
      </el-tab-pane>

      <el-tab-pane label="政策文件" name="six">
        <!-- <Table
          :tableColumn="tableColumn"
          :tableData="tableData"
          :activeName="activeName"
        ></Table> -->
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import Table from './components/table'

import {
  tzzfindList,
  tzzfindWtList,
  selectByDueTime,
  tzzfindYclList,
} from '@/api/grid'

export default {
  name: 'DailyOffice',
  components: { Table },
  props: {},
  data() {
    return {
      activeName: 'first',
      tableColumn: [
        {
          prop: 'gDescribe',
          label: '情况描述',
        },
        {
          prop: 'gTaskName',
          label: '主体名称',
        },
        {
          prop: 'gCrtDt',
          label: '创建时间',
        },

        {
          prop: 'gPreTaskName',
          label: '填报来源',
        },
      ],
      tableColumn1: [
        {
          prop: 'gDescribexc',
          label: '情况描述',
        },
        {
          prop: 'gTaskName',
          label: '主体名称',
        },
        {
          prop: 'gCrtDt',
          label: '创建时间',
        },

        {
          prop: 'gPreTaskName',
          label: '填报来源',
        },
      ],
      MypatrolColumn: [
        {
          prop: 'gDescribecl',
          label: '情况描述',
        },
        {
          prop: 'gTaskName',
          label: '主体名称',
        },
        {
          prop: 'gCrtDt',
          label: '创建时间',
        },

        {
          prop: 'gPreTaskName',
          label: '填报来源',
        },
      ],
      tableData: [
        //   {
        //     title: '群众举报-1',
        //     time: '2021-03-27',
        //     local: '188.8,256.2',
        //     location: '河北省-石家庄-x x县-y y村',
        //   },
        //   {
        //     title: '巡视问题-1',
        //     time: '2021-03-29',
        //     local: '188.8,256.2',
        //     location: '河北省-石家庄-x x县-y y村',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-04',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1516 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-01',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1517 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-08',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1518 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-06',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1518 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-07',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1519 弄',
        //   },
        //   {
        //     title: '群众举报-1',
        //     time: '2021-03-27',
        //     local: '188.8,256.2',
        //     location: '河北省-石家庄-x x县-y y村',
        //   },
        //   {
        //     title: '巡视问题-1',
        //     time: '2021-03-29',
        //     local: '188.8,256.2',
        //     location: '河北省-石家庄-x x县-y y村',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-04',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1516 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-01',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1517 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-08',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1518 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-06',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1518 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-07',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1519 弄',
        //   },
        //   {
        //     title: '群众举报-1',
        //     time: '2021-03-27',
        //     local: '188.8,256.2',
        //     location: '河北省-石家庄-x x县-y y村',
        //   },
        //   {
        //     title: '巡视问题-1',
        //     time: '2021-03-29',
        //     local: '188.8,256.2',
        //     location: '河北省-石家庄-x x县-y y村',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-04',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1516 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-01',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1517 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-08',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1518 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-06',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1518 弄',
        //   },
        //   {
        //     title: '王小虎',
        //     time: '2016-05-07',
        //     local: '188.8,256.2',
        //     location: '上海市普陀区金沙江路 1519 弄',
        //   },
      ],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      glevel: '',
      tableData1: {},
    }
  },
  computed: {},
  watch: {},
  beforeCreate() {
    // const loading = this.$loading({
    //   lock: true,
    //   text: 'Loading',
    //   spinner: 'el-icon-loading',
    //   background: 'rgba(0, 0, 0, 0.7)',
    // })
    // tzzfindList({})
    //   .then((res) => {
    //     loading.close()
    //     // this.$message({
    //     //   message: res.message,
    //     //   type: 'success',
    //     // })
    //     this.tableData = res.data
    //   })
    //   .catch((err) => {
    //     loading.close()
    //     console.log(err)
    //   })
  },
  created() {},
  beforeMount() {
    this.glevel = JSON.parse(sessionStorage.userInfo).glevel
    // console.log(JSON.parse(sessionStorage.userInfo).glevel)
    if (this.glevel !== 2) {
      this.activeName = 'second'
    }
    // if (this.activeName !== 'first') {
    //   this.tableColumn = this.MypatrolColumn
    // }
    this.publicList()
  },
  mounted() {},
  methods: {
    handleClick(tab, event) {
      // this.publicList()
      // if (tab.name === 'first') {
      //   location.reload()
      // }

      if (tab.name === 'first') {
        // console.log(tab, event)
        // console.log(this.activeName)
        this.publicList()
        this.$refs.child.toBack()
        this.tableColumn = this.MypatrolColumn
        if (tab.name === 'first' && this.glevel === 2) {
          location.reload()
        }
      } else if (tab.name === 'second') {
        this.publicList()
        this.$refs.child.toBack()
        // if (this.glevel !== 2) {
        //   location.reload()
        // }
        // this.MypatrolList()
        // this.tableColumn = this.tableColumn1
      } else if (tab.name === 'third') {
        this.$refs.child.toBack()
        this.MyZGList()
      } else if (tab.name === 'fourth') {
        this.publicList()
        this.$refs.child.toBack()

        // this.MypatrolList()
        // this.tableColumn = this.tableColumn1
      } else if (tab.name === 'five') {
        // this.publicList()
        // this.$refs.child.toBack()
        this.tzzfindYclList()
        this.$refs.child.toBack()
        // this.tableColumn = this.tableColumn1
      }
    },
    // 公共举报
    publicList() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
      })
      // tzzfindList({ pageNum: this.pageNum, pageSize: this.pageSize })
      tzzfindList({})
        .then((res) => {
          // console.log(res.data)
          loading.close()
          // this.$message({
          //   message: res.message,
          //   type: 'success',
          // })
          this.tableData = []
          let tableData1 = []
          this.total = 0
          res.data.forEach((v, i) => {
            // res.data[i].gCrtDt = v.gCrtDt.substring(0, 10)
            res.data[i].gCrtDt = this.utilChangeDate(v.gCrtDt)
          })

          res.data.forEach((v, i) => {
            if (
              v.gTaskName.indexOf('群众举报') >= 0 &&
              this.activeName === 'first' &&
              this.glevel === 2
            ) {
              // console.log(v)
              tableData1.push(v)
              this.tableData = tableData1
              this.total = this.tableData.length
            } else if (
              v.gTaskName.indexOf('下级反馈') >= 0 &&
              this.activeName === 'second' &&
              this.glevel !== 2
            ) {
              // console.log(v)
              tableData1.push(v)
              this.tableData = tableData1
              this.total = this.tableData.length
            } else if (
              v.gTaskName.indexOf('巡视问题') >= 0 &&
              this.activeName === 'second'
            ) {
              tableData1.push(v)
              this.tableData = tableData1
              this.total = this.tableData.length
            } else if (
              v.gTaskName.indexOf('上级督办') >= 0 &&
              this.activeName === 'fourth'
            ) {
              tableData1.push(v)
              this.tableData = tableData1
              // console.log(tableData)
              this.total = this.tableData.length
            }
            // else if (
            //   v.gTaskName.indexOf('结果上报') >= 0 &&
            //   this.activeName === 'five'
            // ) {
            //   tableData1.push(v)
            //   this.tableData = tableData1
            //   // console.log(tableData)
            //   this.total = this.tableData.length
            // }
          })

          if (this.activeName !== 'first') {
            // console.log(this.tableData)
            this.tableData.forEach((v, i) => {
              if (v.gDescribecl) {
                this.tableColumn = this.MypatrolColumn
              } else if (v.gDescribexs) {
                this.tableColumn = this.tableColumn1
              }
            })
          }

          // this.total = res.data.total
          // this.tableData = res.data
        })
        .catch((err) => {
          loading.close()
          console.log(err)
        })
    },
    // // 整改到期
    // Dueto() {
    //   const loading = this.$loading({
    //     lock: true,
    //     text: 'Loading',
    //     spinner: 'el-icon-loading',
    //     background: 'rgba(0, 0, 0, 0.7)',
    //   })
    //   selectByDueTime({ pageNum: this.pageNum, pageSize: this.pageSize })
    //     .then((res) => {})
    //     .catch((err) => {
    //       loading.close()
    //       console.log(err)
    //     })
    // },
    // 我的巡视
    MypatrolList() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
      })
      tzzfindWtList({ pageNum: this.pageNum, pageSize: this.pageSize })
        .then((res) => {
          loading.close()
          // this.$message({
          //   message: res.message,
          //   type: 'success',
          // })
          // this.total = res.data.total
          // this.tableData = res.data

          res.data.forEach((v, i) => {
            // console.log(v, i)
            res.data[i].gCrtDt = this.utilChangeDate(v.gCrtDt)
          })
          // this.tableData = {}
          res.data.forEach((v, i) => {
            if (v.gtaskName.indexOf('巡视问题') >= 0) {
              console.log(v.gtaskName, i)
              this.total = i - 1
              let tableData2 = []
              tableData2.push(v)
              this.tableData = tableData2
            }
          })

          // console.log(this.total)
        })
        .catch((err) => {
          loading.close()
          console.log(err)
        })
    },
    // 整改到期
    MyZGList() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
      })
      selectByDueTime({ pageNum: this.pageNum, pageSize: this.pageSize })
        .then((res) => {
          loading.close()
          // this.$message({
          //   message: res.message,
          //   type: 'success',
          // })
          this.total = res.data.total
          this.tableData = res.data.list

          res.data.list.forEach((v, i) => {
            // console.log(v, i)
            res.data.list[i].gCrtDt = this.utilChangeDate(v.gCrtDt)
          })

          // console.log(this.total)
        })
        .catch((err) => {
          loading.close()
          console.log(err)
        })
    },
    page(form) {
      form.forEach((v, i) => {
        // console.log(v, i)
        form[i].gCrtDt = v.gCrtDt.substring(0, 10)
      })
      this.tableData = form
    },
    // five 已处理
    tzzfindYclList() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
      })
      tzzfindYclList({})
        .then((res) => {
          loading.close()
          // this.$message({
          //   message: res.message,
          //   type: 'success',
          // })

          res.data.forEach((v, i) => {
            // console.log(v, i)
            res.data[i].gCrtDt = this.utilChangeDate(v.gCrtDt)
          })

          this.tableColumn = this.tableColumn1

          this.total = res.data.total
          this.tableData = res.data
        })
        .catch((err) => {
          loading.close()
          console.log(err)
        })
    },

    utilChangeDate(dateStr) {
      if (!dateStr) {
        return ''
      }
      var date = new Date(dateStr)
      var y = date.getFullYear()
      var m = date.getMonth() + 1
      m = m < 10 ? '0' + m : m
      var d = date.getDate()
      d = d < 10 ? '0' + d : d
      var h = date.getHours()
      h = h < 10 ? '0' + h : h
      var minute = date.getMinutes()
      minute = minute < 10 ? '0' + minute : minute
      var second = date.getSeconds()
      second = second < 10 ? '0' + second : second
      return y + '-' + m + '-' + d
    },
  },
}
</script>

<style scoped lang="scss">
</style>
